package www.com.springboot_20200312.rabbitmqDemo.Demo07Message.consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import www.com.springboot_20200312.rabbitmqDemo.Demo07Message.message.Demo07Message;

/**
 * @program: springboot_20200312
 * @ClassName Demo07Consumer
 * @description:
 * @author: jht
 * @create: 2021-12-07 15:22
 * @Version 1.0
 **/

@Component
@RabbitListener(queues = Demo07Message.QUEUE)
public class Demo07Consumer {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @RabbitHandler
    public void onMessage(Demo07Message message) {
        logger.info("[onMessage][线程编号:{} 消息内容：{}]", Thread.currentThread().getId(), message);
        // <X> 注意，此处抛出一个 RuntimeException 异常，模拟消费失败
        logger.info("模拟消费失败");
        throw new RuntimeException("我就是故意抛出一个异常");

    }

}